stage.set_background("moon")
sprite = codesters.Sprite("hedgehog", 0, -210)
score = 0
#my_display = codesters.Display(my_var, x, y)
score_display = codesters.Display(score, -210, -210)
time = 60
#my_display = codesters.Display(my_var, x, y)
time_display = codesters.Display(time, 210, -210)
def left_key():
rotation = sprite.get_rotation()
print(rotation)
sprite.set_rotation(rotation+3)
# add other actions...
stage.event_key("left", left_key)
def right_key():
rotation = sprite.get_rotation()
print(rotation)
sprite.set_rotation(rotation-3)
# add other actions...
stage.event_key("right", right_key)
def interval():
global time
time -=1
time_display.update(time)
stage.event_interval(interval, 2)
t = codesters.Teacher()
params = t.get_parameters_for_function('event_interval')
call = t.find_text('event_interval')
try:
tval1 = int(params[0][1])
except:
tval1 = -1
try:
call_line = int(call[0][0])
call_line_indent = t.get_indent_at_line(call_line)
except:
call_line = -1
call_line_indent = -1
t1 = TestObjective()
t1.add_success(tval1 == 1 and call_line_indent == 0, "Great job!")
t1.add_failure(tval1 == 2, "Did you change the number in the interval event handler?")
t1.add_failure(tval1 != 1, "Did you change the interval correctly?")
t1.add_failure(call_line_indent != 0, "Oops! Don't indent the event handler!")
tester = TestManager()
tester.add_test_list([t1])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)